package com.yu1996.article.controller;

import com.yu1996.article.pojo.Comment;
import com.yu1996.article.service.CommentService;
import entity.Result;
import entity.StatusCode;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@CrossOrigin
@RequestMapping("/comment")
public class CommentController {

    @Autowired
    private CommentService commentService;

    /**
     * @param comment
     * @return entity.Result
     * @description 添加评论
     * @date 2019/10/14 9:24
     */
    @RequestMapping(method = RequestMethod.POST)
    public Result add(@RequestBody Comment comment) {
        commentService.add(comment);
        return new Result(true, StatusCode.OK, "评论成功");
    }


    @RequestMapping(value = "/article/{articleid}", method = RequestMethod.GET)
    public Result findById(@PathVariable String articleid) {
        return new Result(true, StatusCode.OK, "查询成功", commentService.findById(articleid));
    }

    @RequestMapping(value = "/article/{articleid}", method = RequestMethod.DELETE)
    public Result delete(@PathVariable String articleid) {
        commentService.delete(articleid);
        return new Result(true, StatusCode.OK, "删除成功");
    }
}
